package com.changgou.goods.dao;

import com.changgou.goods.pojo.Sku;
import com.changgou.order.pojo.OrderItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

public interface SkuMapper extends Mapper<Sku> {
    /**
     * 扣减库存并增加销量
     *
     * @param orderItem
     * @return int
     * @throws
     * @description
     * @author kfzhao
     * @date 2022/1/3 17:27
     */
    @Update("update tb_sku set num=num-#{num}, sale_num=sale_num+#{num} where id=#{skuId} and num>=#{num};")
    int decrCount(OrderItem orderItem);


    /**
     * 回滚库存：增加库存并扣减销量
     *
     * @param skuId 商品id
     * @param num 要回滚的数量
     * @return void
     * @throws
     * @description
     * @author kfzhao
     * @date 2022/1/5 0:25
     */
    @Update("update tb_sku set num=num+#{num}, sale_num=sale_num-#{num} where id=#{skuId};")
    void resumeStockNum(@Param("skuId") String skuId, @Param("num") Integer num);
}
